import { dedent } from 'vtils';

import { InterfaceCodeTemplateData, GetApiNamesType, Interface } from '../types';

export const configTemplate = `
module.exports = [
  {
    /**
     * YApi 服务地址
     * @example https://yapi.baibu.la/
     */
    serverUrl: '',
    /**
     * 输出的文件夹，默认 './src/api'
     */
    outputFilePath: '',
    projects: [
      {
        /**
         * 项目token
         * 项目名称：
         */
        token: '',
        /**
          * 可选配置
          * 需要排除的接口分类id
          * @type number | number[] 
          */
        excludeCatIds: [],
        /**
          * 可选配置
          * 需要排除的接口id
          * @type number | number[] 
          */
         excludeApiIds: [],
        /**
          * 可选配置
          * 需要输出的接口分类id
          * @type number | number[] 
          */
        includeCatIds: [],
        /**
          * 可选配置
          * 需要输出的接口id
          * @type number | number[] 
          */
         includeApiIds: [],
         /**
          * 可选配置
          * 处理输出api目录，ps：基于 outputFilePath 下的目录
          * @param apiData 接口yapi json
          * @param changeCase @see https://www.npmjs.com/package/change-case
          * @returns api目录名
          */
         getApiDir(apiData, changeCase) {
           /** */
         },
         /**
         * 自定义接口函数名称、出参入参数据类型名称
         * @param apiData 接口yapi json
         * @param changeCase @see https://www.npmjs.com/package/change-case
         * @returns { requestFunctionName: string; requestDataTypeName: string; responseDataTypeName: string; }
         */
         getApiNames(apiData, changeCase) {
           /** */
         },
      }
    ]
  },
];
`;

/**
 * 数据类型模板
 */
export const interfaceCodeTemplate = (data: InterfaceCodeTemplateData) => {
  return dedent`
    /**
     * **请求类型**
     * ${data.interfaceApiTitle}
     * @see ${data.interfaceApiUrl}
     *
     ${data.interfaceExtraComments}
    */
    ${data.requestDataType.trim()}

    /**
     * **返回类型**
     * ${data.interfaceApiTitle}
     * @see ${data.interfaceApiUrl}
     *
     ${data.interfaceExtraComments}
    */
    ${data.responseDataType.trim()}
  `;
};

/**
 * 获取 api模板
 */
export const fetchApiCodeTemplate = (data: GetApiNamesType, interfaceInfo: Interface) => {
  return dedent`
    /**
     * ${data.interfaceApiTitle}
     * @see ${data.interfaceApiUrl}
     *
     ${data.interfaceExtraComments}
    */
     export const ${data.requestFunctionName} = () => {
        return http.${(interfaceInfo.method || '').toLocaleLowerCase()}<Types.${
    data.responseDataTypeName
  }>({
          url: ${interfaceInfo.path}
        })
     };
  `;
};

export const fetchApiModulesImport = dedent`
  import http from '@/http';
`;
